package com.majie.algorithm.queue;


import java.util.Stack;

public class Queue<E> {

    private Stack<E> in = new Stack<>();
    private Stack<E> out = new Stack<>();

    private int size = 0;

    public void push(E element) {
        while (out.size() > 0) {
            in.push(out.pop());
        }
        in.push(element);
        size++;
    }

    public E pop( ) {
        E element;
        while (in.size() > 0) {
            out.push(in.pop());
        }
        element = out.pop();
        size--;
        return element;
    }

    public E peek( ) {
        while (in.size() > 0) {
            out.push(in.pop());
        }
        return out.peek();
    }

    public int size( ) {
        return this.size;
    }

    public static void main(String[] args) {
        Queue<Integer> queue = new Queue<>();
        for (int i = 0; i < 10; i++) {
            queue.push(i);
        }

        while (queue.size() > 5) {
            System.out.println(queue.pop());
        }
        queue.push(55);
        while (queue.size() > 0) {
            System.out.println(queue.pop());
        }
    }
}
